<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>echarts</title>
    <style>
        body {
            background-color: #f7f8fa;
        }
        .charts-container{
            display: grid;
            gap: 10px;
            grid-template-columns: 1fr 1fr 1fr;
        }
        .charts-item{
            background-color: #fff;
        }
    </style>
</head>
<body>
    <div class="charts-container">
        <div class="charts-item" id="main" style="width: 600px;height:400px;"></div>
        <div class="charts-item" id="main1" style="width: 600px;height:400px;"></div>
        <div class="charts-item" id="main2" style="width: 600px;height:400px;"></div>

    </div>

    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>

    <script>
        $(function(){
            $.ajax({
                url:'zt.php',
                success(res){
                    console.log(res)
                    Chart1(res.data.x,res.data.y)
                    Chart2(res.data.zt)
                    Chart3(res.data.a,res.data.b)

                },
                error(){
                    alert('请求失败')
                }
            })
        });
    </script>
    <script type="text/javascript">
        function Chart1(x,y) {
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('main'));

            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '职位人数柱状图'
                },
                tooltip: {},
                legend: {
                    data: ['人数']
                },
                xAxis: {
                    data: x
                },
                yAxis: {},
                series: [
                    {
                        name: '人数',
                        type: 'bar',
                        data: y
                    }
                ]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }

        function Chart2(zt) {
            var chartDom = document.getElementById('main1');
            var myChart = echarts.init(chartDom);
            var option = {
                title: {
                    text: '职位人数饼图',
                    subtext: '',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: 'Access From',
                        type: 'pie',
                        radius: '50%',
                        data: zt,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };

            option && myChart.setOption(option);

        }

        function Chart3(a,b){
            var chartDom = document.getElementById('main2');
            var myChart = echarts.init(chartDom);
            option = {
                xAxis: {
                    type: 'category',
                    data: a
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: b,
                        type: 'line'
                    }
                ]
            };
        }

    </script>
</body>
</html>